 

const cloud = require('wx-server-sdk')

//云开发环境初始化
cloud.init({
 env: 'cloud1-7g1a0u3je2bf6f8d', //所对应的环境ID
 traceUser: true
})


exports.main = async (event, context) => {
 const wxContext = cloud.getWXContext()
 try {
   const result = await cloud.openapi.wxacode.getUnlimited({
       page:  event.page,
      // openid: event.openid,
       scene: event.scene,
      //envVersion: 'develop',
        
       width: 240

     })
  // return result

       // 上传到云存储
       const uploadResult = await cloud.uploadFile({
         cloudPath: 'qr/' + new Date().getTime() + '.jpg',
         fileContent: result.buffer,
       });
       // return uploadResult;
       if (!uploadResult.fileID) {
         //上传失败，返回错误信息
         return uploadResult;
       }
   
       // 获取图片临时路径
       getURLReault = await cloud.getTempFileURL({
         fileList: [uploadResult.fileID]
       });
       fileObj = getURLReault.fileList[0];
       fileObj.fromCache = false;
   
       // 上传成功，获取文件临时url，返回临时路径的查询结果
       return fileObj;

 }catch (err) {
   return err
 }







}